﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using StockShark.Models;

namespace StockShark.ViewModels
{
    public class PeriodList
    {
        public static List<SelectListItem> GetSelectList(string selected)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem { Text = "Tydzień", Value = "week", Selected = (selected.Equals("week")) });
            list.Add(new SelectListItem { Text = "2 tygodnie", Value = "2weeks", Selected = (selected.Equals("2weeks")) });
            list.Add(new SelectListItem { Text = "Miesiąc", Value = "month", Selected = (selected.Equals("month")) });
            list.Add(new SelectListItem { Text = "3 miesiące", Value = "3months", Selected = (selected.Equals("3months")) });
            list.Add(new SelectListItem { Text = "6 miesięcy", Value = "6months", Selected = (selected.Equals("6months")) });
            list.Add(new SelectListItem { Text = "Rok", Value = "year", Selected = (selected.Equals("year")) });
            list.Add(new SelectListItem { Text = "Od początku", Value = "all", Selected = (selected.Equals("all")) });
            return list;
        }

        public static DateTime GetStartDate(string period)
        {
            if (period.ToLower().Equals("week"))
            {
                return DateTime.Today.AddDays(-7);
            }
            else if (period.ToLower().Equals("2weeks"))
            {
                return DateTime.Today.AddDays(-14);
            }
            else if (period.ToLower().Equals("month"))
            {
                return DateTime.Today.AddMonths(-1);
            }
            else if (period.ToLower().Equals("3months"))
            {
                return DateTime.Today.AddMonths(-3);
            }
            else if (period.ToLower().Equals("6months"))
            {
                return DateTime.Today.AddMonths(-6);
            }
            else if (period.ToLower().Equals("year"))
            {
                return DateTime.Today.AddYears(-1);
            }
            throw new NotSupportedException();
        }
    }
}